# -*- coding: utf-8 -*-
'''
Created on 2012-9-1

@author: xiaolei
'''
from sqlalchemy import Column, Integer, Unicode, DateTime
from dao.engine import Model
import json
from datetime import datetime, date, time

class User(Model):
    __tablename__ = "user";

    id = Column(Integer, primary_key=True, nullable=False, autoincrement=True);
    display_name = Column(Unicode(255), nullable=False);
    password = Column(Unicode(2048), nullable=True);
    email = Column(Unicode(255), nullable=False, unique=True);
    created_time = Column(DateTime, default=datetime.now);
    updated_time = Column(DateTime, onupdate=datetime.now);
    is_active = Column(Integer, default=1, nullable=False)

    def __init__(self):
        pass;

    def __repr__(self):
        result = {k:getattr(self, k) if not getattr(self, k).__class__ in (datetime, date, time) else str(getattr(self, k)) for k in dir(self) if k in self.__table__.columns};
        return json.dumps(result);

